//
//  UtilsMacro.h
//  BabyNow
//
//  Created by 刘泽琛 on 14-3-28.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#ifndef BabyNow_UtilsMacro_h
#define BabyNow_UtilsMacro_h

/**
 *  上传进度处理器
 *
 *  @param process 上传进度
 */
typedef void(^UploadProcessingHandler)(double process);

/**
 *  已结束请求处理器
 *
 *  @param result       处理结果
 *  @param errorMessage 错误消息
 */
typedef void(^DidFinishRequestHandler) (id result,NSString *errorMessage);

// 数据处理完毕的回调block
typedef void(^ DataHandleComplete) (id result,NSString *errMsg);

// 沙箱缓存路径
#define DIR_PATH_FOR_CACHE NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]

// 网络请求超时时间(s)
#define NET_REQUEST_TIME_OUT 3

// 网络请求方法
#define NET_REQUEST_GET     @"GET"
#define NET_REQUEST_POST    @"POST"

// 网络请求出错信息
// 网络无法访问
#define NET_ERROR_MSG_FOR_NET_NOT_ACCESS              @"请检查您的网络设置"

// 不能满足查询条件的枚举
typedef enum{
    // 可以执行网络请求
    ENUM_CAN_NET_REQUEST,
    // 无法执行网络请求_没有必要属性
    ENUM_CANNOT_NET_REQUEST_FOR_MISSING_PROP_NEEDED,
    // 无法执行网络请求_没有数据处理器
    ENUM_CANNOT_NET_REQUEST_FOR_DATA_HANDLER_NOT_EXIST,
    // 无法执行网络请求_之前的请求还未结束
    ENUM_CANNOT_NET_REQUEST_FOR_PREV_REQUEST_NOT_FINISHED,
    // 无法执行网络请求_网络不通
    ENUM_CANNOT_NET_REQUEST_FOR_WIFI_OR_3G_NOT_ACCESS,
    // 无法执行网络请求_服务器无法访问
    ENUM_CANNOT_NET_REQUEST_FOR_SERVER_NOT_ACCESS
    
} ENUM_CAN_NET_REQUEST_OR_NOT;

// HTTP STATUS CODE
typedef enum {
    ENUM_HTTP_STATUS_OK = 200,
    ENUM_HTTP_STATUS_NET_IF_NOT_IMP = 405,
    ENUM_HTTP_STATUS_NET_IF_NOT_EXIST = 404,
    ENUM_HTTP_STATUS_NET_IF_REQUEST_METHOD_ERROR = 403,
    ENUM_HTTP_STATUS_NET_IF_SERVER_EXCEPTION = 500
}ENUM_HTTP_STATUS;

// CONNECTION ERROR MSG
#define CONNECTION_ERROR_MSG_FOR_NET_SET                    @"请检查您的网络设置"
#define CONNECTION_ERROR_MSG_FOR_UNKNOW                     @"未知的网络请求错误"
#define CONNECTION_ERROR_MSG_FOR_BAD_URL                    @"请求地址异常或请求方法有误"
#define CONNECTION_ERROR_MSG_FOR_UNSUPPORT_URL              @"请求地址不支持"
#define CONNECTION_ERROR_MSG_FOR_NOT_FIND_HOST              @"无法找到服务器"
#define CONNECTION_ERROR_MSG_FOR_NOT_REACH_HOST             @"无法访问服务器"
#define CONNECTION_ERROR_MSG_FOR_TIME_OUT                   @"网络不给力或请求超时"

// HTTP STATUS ERROR MSG
#define NET_ERROR_MSG_FOR_HTTP_STATUS_UNKNOW          @"未知错误"
#define NET_ERROR_MSG_FOR_NET_IF_EXCEPTION            @"服务器接口异常"     // HTTP status code:505
#define NET_ERROR_MSG_FOR_NET_IF_NOT_IMP              @"请求接口暂未实现"   //  HTTP status code:405
#define NET_ERROR_MSG_FOR_NET_IF_NOT_EXIST            @"请求的接口不存在"   //  HTTP status code:404
#define NET_ERROR_MSG_FOR_NET_IF_REQUEST_METHOD_ERROR @"客户端请求方法错误"  //  HTTP status code 403



#define NET_ERROR_MSG_FOR_RESPONSE_JSON_DATA @"数据返回异常"
#define NET_ERROR_MSG_FOR_NO_DATA            @"暂无数据"
#define NET_ERROR_MSG_FOR_NO_MORE_DATA       @"没有更多数据了"


// 文件的MIME类型

// 图片文件MIME类型
#define FILE_MIME_TYPE_FOR_PNG @"image/png"
// mp4文件MIME类型
#define FILE_MIME_TYPE_FOR_MP4 @"video/mp4"


//适配IPhone5、IOS7

#define IPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_IOS_7 ([[UIDevice currentDevice].systemVersion floatValue] >= 7)

//定义屏幕尺寸及中心坐标 定义高清屏
#define kSCREEN_WIDTH [UIScreen mainScreen].applicationFrame.size.width
#define kSCREEN_HEIGHT [UIScreen mainScreen].applicationFrame.size.height
#define kScreen_CenterX  kScreen_Width/2
#define kScreen_CenterY  kScreen_Height/2
#define isRetina ([[UIScreen mainScreen] scale]==2)

//可拉伸的图片

#define IMAGE(name) [UIImage imageNamed:name]
#define ResizableImage(name,top,left,bottom,right) [IMAGE(name) resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)]
#define ResizableScaleImage(name,zoom,top,left,bottom,right) [[UIImage imageWithCGImage:IMAGE(name).CGImage scale:zoom orientation:UIImageOrientationUp] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)]

//获取view的frame某值
#define ViewWidth(v)                        v.frame.size.width
#define ViewHeight(v)                       v.frame.size.height
#define ViewX(v)                            v.frame.origin.x
#define ViewY(v)                            v.frame.origin.y


//获取rect中某值
#define RectX(rect)                            rect.origin.x
#define RectY(rect)                            rect.origin.y
#define RectWidth(rect)                        rect.size.width
#define RectHeight(rect)                       rect.size.height
//设置rect中某值
#define RectSetWidth(rect, w)                  CGRectMake(RectX(rect), RectY(rect), w, RectHeight(rect))
#define RectSetHeight(rect, h)                 CGRectMake(RectX(rect), RectY(rect), RectWidth(rect), h)
#define RectSetX(rect, x)                      CGRectMake(x, RectY(rect), RectWidth(rect), RectHeight(rect))
#define RectSetY(rect, y)                      CGRectMake(RectX(rect), y, RectWidth(rect), RectHeight(rect))

#define RectSetSize(rect, w, h)                CGRectMake(RectX(rect), RectY(rect), w, h)
#define RectSetOrigin(rect, x, y)              CGRectMake(x, y, RectWidth(rect), RectHeight(rect))

//  主要单例
#define UserDefaults                        [NSUserDefaults standardUserDefaults]
#define NotificationCenter                  [NSNotificationCenter defaultCenter]
#define SharedApplication                   [UIApplication sharedApplication]

#define Bundle                              [NSBundle mainBundle]
#define MainScreen                          [UIScreen mainScreen]

//  主要控件
#define NavBar                              self.navigationController.navigationBar
#define NavItem                             self.navigationItem
#define TabBar                              self.tabBarController.tabBar

//输出frame(frame是结构体，没法%@) BOOL NSInteger
#define LOGFRAME(f) NSLog(@"\nx:%f\ny:%f\nwidth:%f\nheight:%f\n",f.origin.x,f.origin.y,f.size.width,f.size.height)
#define LOGBOOL(b)  NSLog(@"%@",b?@"YES":@"NO");
#define NSStringFromInt(intValue) [NSString stringWithFormat:@"%d",intValue]
#define LOGINT(i) NSLog(@"%@",NSStringFromInt(i))
//弹出信息
#define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil] show]

//color
#define RGB(r, g, b)             [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0]
#define RGBAlpha(r, g, b, a)     [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)]

#define HexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define HexRGBAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]
#define PatternImageByColor(color) [ColorToImage imageWithColor:color]

//转换
#define I2S(number) [NSString stringWithFormat:@"%d",number]
#define F2S(number) [NSString stringWithFormat:@"%f",number]
#define DATE(stamp) [NSDate dateWithTimeIntervalSince1970:[stamp intValue]];

//GCD （子线程、主线程定义）
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//打开URL
#define canOpenURL(appScheme) ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appScheme]])

#define openURL(appScheme) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:appScheme]])

// 系统配置

//版本号
#define MAIN_VERSION [[[[UIDevice currentDevice]systemVersion]componentsSeparatedByString:@"."][0] integerValue]

// 格式化字符
#define FORMAT_STR(params) [NSString stringWithFormat:@"%@",params]

// 格式化数值
#define FORMAT_INT(params) [parsms integerValue]


// 是否是IOS7
#define IOS7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0

// 屏幕宽度
#define SCREEN_WIDTH    [[UIScreen mainScreen] applicationFrame].size.width

// 屏幕高度
#define SCREEN_HEIGHT   [[UIScreen mainScreen] applicationFrame].size.height

// 屏幕高度
#define FULLSCREEN_HEIGHT  [UIScreen mainScreen].bounds.size.height

// 导航栏高度
#define HEIGHT_NAV_BAR 44

// 标签栏高度
#define HEIGHT_TAB_BAR 49

// 是否是iPhone5
#define IS_iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

// 是否第一次启动
#define FIRSTRUN @"FIRSTRUN"

#endif
